package com.cy.deepseeksport.service.search;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
class BochaApiResponse {
    private Integer code;
    private String log_id;
    private String conversation_id;
    private List<Message> messages;

    @Data
    public static class Message {
        private String role;
        private String type;
        @JsonProperty("content_type")
        private String contentType;
        private String content;

        // 根据content_type不同，content可能是不同结构
        // 可以添加辅助方法获取特定类型的内容
        public <T> T getContentAs(Class<T> valueType) {
            try {
                return new ObjectMapper().readValue(content, valueType);
            } catch (JsonProcessingException e) {
                throw new RuntimeException("Failed to parse content", e);
            }
        }
    }
}

// 网页信息内容
@Data
class WebpageContent {
    private String webSearchUrl;
    private List<Webpage> value;
    private Boolean someResultsRemoved;

    @Data
    public static class Webpage {
        private String id;
        private String name;
        private String url;
        private String displayUrl;
        private String snippet;
        private String summary;
        private String siteName;
        private String siteIcon;
        private String dateLastCrawled;
    }
}

